{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a6c63275",
   "metadata": {},
   "source": [
    "## 循环结构\n",
    "\n",
    "Python 提供了 for 循环和 while 循环（在 Python 中没有 do..while 循环）:\n",
    "\n",
    "| 循环类型\t| 描述\n",
    "|:-----|:-----|\n",
    "|while 循环  |在给定的判断条件为 true 时执行循环体，否则退出循环体。\n",
    "|for 循环\t  |重复执行语句\n",
    "|嵌套循环\t|你可以在while循环体中嵌套for循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b0e7d61b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "tang =0\n",
    "while tang<10:\n",
    "    print(tang)\n",
    "    tang+=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "20dfe47d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "di\n",
      "yu\n",
      "tang\n"
     ]
    }
   ],
   "source": [
    "tangs = (['tang','yu','di'])\n",
    "while tangs:\n",
    "    tang = tangs.pop()\n",
    "    print(tang)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b7f72a12",
   "metadata": {},
   "outputs": [],
   "source": [
    "tangs = set(['tang','yu','di'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d108fcd7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "yu\n",
      "tang\n",
      "di\n"
     ]
    }
   ],
   "source": [
    "for name in tangs:\n",
    "    print(name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "23e28bcb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123\n",
      "456\n",
      "789\n",
      "121\n",
      "122\n",
      "133\n",
      "221\n",
      "324\n",
      "211\n",
      "345\n"
     ]
    }
   ],
   "source": [
    "tang=[123,456,789,121,122,133,221,324,211,345]\n",
    "for i in range(len(tang)):\n",
    "    print(tang[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f97ff6be",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "tang=[10,11,12,13,14,15]\n",
    "for i in tang:\n",
    "    if i%2==0:\n",
    "        print(i)\n",
    "    else:\n",
    "        break\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8a285b27",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
